<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .nav{
            width: 100%;
            height: 50px;
            position: fixed;
            background-color: orangered;
            opacity: 0;
        }
        body{
            height: 2000px;
        }
    </style>
</head>
<body>
    <div class="nav"></div>
    <script>
        var nav = document.getElementsByClassName("nav")[0];
       window.onscroll = function () {
        var scrollTop = document.documentElement.scrollTop;
        console.log(scrollTop)
        var opacity = scrollTop/500;
        if(opacity>1){
            opacity=1;
        }
        nav.style.opacity = opacity;

        
         }
    </script>
</body>
</html>